import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [

  {
    title: '组',
    align: "center",
    sorter: true,
    dataIndex: 'resourceGroup'
  },
  //  {
  //   title: '组id',
  //   align:"center",
  //   dataIndex: 'resourceGroupId'
  //  },
  {
    title: '分类',
    align: "center",
    dataIndex: 'resourceClassId'
  },
  {
    title: '编码',
    align: "center",
    sorter: true,
    dataIndex: 'resourceCoding'
  },
  {
    title: '名称',
    align: "center",
    dataIndex: 'resourceName'
  },
  {
    title: '规格',
    align: "center",
    dataIndex: 'resourceSpecification'
  },
  {
    title: '车间自编号',
    align: "center",
    sorter: true,
    dataIndex: 'workshopSelfNumbering'
  },
  //  {
  //   title: '车间Id',
  //   align:"center",
  //   dataIndex: 'workshopId'
  //  },
  {
    title: '数量',
    align: "center",
    sorter: true,
    dataIndex: 'quantity',
    width: '100px'
  },
  {
    title: '单位',
    align: "center",
    dataIndex: 'unit',
    width: '60px'
  },
  //  {
  //   title: '单位id',
  //   align:"center",
  //   dataIndex: 'unitId'
  //  },
  {
    title: '卡片编码',
    align: "center",
    sorter: true,
    dataIndex: 'cardCoding'
  },
  {
    title: '生产厂家',
    align: "center",
    dataIndex: 'manufactureFactory'
  },
  {
    title: '生产厂家编码',
    align: "center",
    dataIndex: 'manufacturerCode'
  },
  //  {
  //   title: '生产厂家编码Id',
  //   align:"center",
  //   dataIndex: 'manufacturerId'
  //  },
  {
    title: '是否专用',
    align: "center",
    width: '100px',
    dataIndex: 'dedicatedNot',
    customRender: ({ text }) => text == 1 ? '是' : '否'
  },
  {
    title: '是否上机',
    align: "center",
    width: '100px',
    dataIndex: 'superiorNot',
    customRender: ({ text }) => {
      return text == 1 ? '是' : '否'
    },
  },
  {
    title: '维保冲次',
    align: "center",
    sorter: true,
    width: '100px',
    dataIndex: 'maintainStrokeTimes'
  },
  // {
  //   title: '使用部门',
  //   align: "center",
  //   dataIndex: 'departmentId'
  // },
  {
    title: '使用部门',
    align: "center",
    dataIndex: 'departmentName'
  },
  {
    title: '启用日期',
    align: "center",
    sorter: true,
    width: '120px',
    dataIndex: 'commissioningDate',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  {
    title: '当前冲次',
    align: "center",
    width: '100px',
    dataIndex: 'currentStroke'
  },
  {
    title: '是否失效',
    align: "center",
    width: '100px',
    dataIndex: 'failureNot',
    customRender: ({ text }) => {
      return text == 1 ? '是' : '否'
    },
  },
  {
    title: '第三方编码',
    align: "center",
    width: '110px',
    dataIndex: 'thirdPartyCode',
    ifShow: false
  },
  {
    title: '备注',
    align: "center",
    width: '80px',
    dataIndex: 'remark'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "组",
    field: "resourceGroup",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "分类",
    field: "resourceClassId",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "编码",
    field: "resourceCoding",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "名称",
    field: "resourceName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "车间自编号",
    field: "workshopSelfNumbering",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "数量",
    field: "quantity",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "卡片编码",
    field: "cardCoding",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "维保冲次",
    field: "maintainStrokeTimes",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "使用部门",
    field: "departmentName",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "启用日期",
    field: "commissioningDate",
    component: 'DatePicker',
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [

  {
    label: '组',
    field: 'resourceGroup',
    component: 'Input',
    slot: 'resourceGroupSlot',
    dynamicRules: () => {
      return [
        { required: true, message: '请输入组!' },
      ];
    },
  },
  {
    label: '组id',
    field: 'resourceGroupId',
    component: 'Input',
    show: false
  },
  {
    label: '分类',
    field: 'resourceClassId',
    component: 'Input',
    dynamicRules: () => {
      return [
        { required: true, message: '请输入分类!' },
      ];
    },
  },
  {
    label: '编码',
    field: 'resourceCoding',
    component: 'Input',
  },
  {
    label: '名称',
    field: 'resourceName',
    component: 'Input',
    dynamicRules: () => {
      return [
        { required: true, message: '请输入名称!' },
      ];
    },
  },
  {
    label: '规格',
    field: 'resourceSpecification',
    component: 'Input',
  },
  {
    label: '车间自编号',
    field: 'workshopSelfNumbering',
    component: 'Input',
  },
  {
    label: '车间Id',
    field: 'workshopId',
    component: 'Input',
    show: false
  },
  {
    label: '数量',
    field: 'quantity',
    component: 'InputNumber',
  },
  {
    label: '单位',
    field: 'unit',
    component: 'Input',
    slot: 'unitSlot'
  },
  {
    label: '单位id',
    field: 'unitId',
    component: 'Input',
    show: false
  },
  {
    label: '卡片编码',
    field: 'cardCoding',
    component: 'Input',
  },
  {
    label: '生产厂家',
    field: 'manufactureFactory',
    component: 'Input',
    slot: 'manufactureFactorySlot'
  },
  // {
  //   label: '生产厂家编码',
  //   field: 'manufacturerCode',
  //   component: 'Input',
  // },
  {
    label: '生产厂家编码Id',
    field: 'manufacturerId',
    component: 'Input',
    show: false
  },
  {
    label: '是否专用',
    field: 'dedicatedNot',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
      stringToNumber: true,
    }
  },
  {
    label: '是否上机',
    field: 'superiorNot',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
      stringToNumber: true,
    }
  },
  {
    label: '维保冲次',
    field: 'maintainStrokeTimes',
    component: 'InputNumber',
  },
  {
    label: '使用部门',
    field: 'departmentName',
    component: 'Input',
    show: false
  },
  {
    label: '使用部门',
    field: 'departmentId',
    component: 'JSelectDept',
    componentProps: ({ }) => {
      return {
        multiple: false,
        showButton: false,
        checkable: false,
        labelKey: 'departName'
      }
    },
  },
  {
    label: '启用日期',
    field: 'commissioningDate',
    component: 'DatePicker',
  },
  {
    label: '当前冲次',
    field: 'currentStroke',
    component: 'InputNumber',
  },
  {
    label: '是否失效',
    field: 'failureNot',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
      stringToNumber: true,
    }
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
    ifShow: false
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const busResourceAdministrationDetailColumns: JVxeColumn[] = [

  // {
  //   title: '组织id',
  //   key: 'organizationId',
  //   type: JVxeTypes.hidden,
  //   width:"200px",
  //   placeholder: '请输入${title}',
  //   defaultValue:'',
  // },
  // {
  //   title: '租户id',
  //   key: 'tenantId',
  //   type: JVxeTypes.inputNumber,
  //   width:"200px",
  //   placeholder: '请输入${title}',
  //   defaultValue:'',
  // },
  // {
  //   title: '删除状态 0正常 1已删除',
  //   key: 'delFlag',
  //   type: JVxeTypes.input,
  //   width:"200px",
  //   placeholder: '请输入${title}',
  //   defaultValue:'',
  // },

  {
    title: '明细日期',
    key: 'detailedDate',
    type: JVxeTypes.date,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '零件图号',
    key: 'partDrawingNumber',
    type: JVxeTypes.input,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '零件',
    key: 'nameParts',
    type: JVxeTypes.input,
    width: "80px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '零件id',
    key: 'namePartsId',
    type: JVxeTypes.hidden,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '使用部门',
    key: 'useDepartmentId',
    type: JVxeTypes.departSelect,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '使用部门id',
    key: 'useDepartmentId',
    type: JVxeTypes.hidden,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '上机时间',
    key: 'computerTime',
    type: JVxeTypes.date,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        handler({ cellValue, row }, callback) {
          let startTime = new Date(cellValue).getTime();
          let endTime = new Date(row.disembarkationTime).getTime();
          if (startTime > endTime) {
            callback(false, '${title}不能大于下机时间')
          } else {
            callback(true);
          }
        }
      }
    ],
  },
  {
    title: '上机人员工号',
    key: 'numberOperator',
    type: JVxeTypes.input,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '上机员工',
    key: 'numberOperatorName',
    type: JVxeTypes.input,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '下机时间',
    key: 'disembarkationTime',
    type: JVxeTypes.date,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        handler({ cellValue, row }, callback) {
          let startTime = new Date(cellValue).getTime();
          let endTime = new Date(row.computerTime).getTime();
          if (startTime < endTime) {
            callback(false, '${title}不能小于上机时间')
          } else {
            callback(true);
          }
        }
      }
    ],
  },
  {
    title: '下机人员工号',
    key: 'numberFinish',
    type: JVxeTypes.input,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '下机员工',
    key: 'numberFinishName',
    type: JVxeTypes.input,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '工作时长',
    key: 'workingHours',
    type: JVxeTypes.inputNumber,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '管理Id',
    key: 'resourceAdministrationId',
    type: JVxeTypes.hidden,
    width: "100px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.input,
    width: "80px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.hidden,
    width: "110px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]


/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}